package com.xgry.bpm.api.base.formcontrol.service.impl;

import com.xgry.bpm.api.base.formcontrol.entity.FormControl;
import com.xgry.bpm.api.base.formcontrol.mapper.FormControlMapper;
import com.xgry.bpm.api.base.formcontrol.service.FormControlService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils;
import org.springframework.util.StringUtils;
import org.apache.http.HttpStatus;

import java.util.List;

/**
* <p>
    * FormControl服务实现类
    * </p>
*
* @author adrian
* @since 2020-07-08
*/
@Service
public class FormControlServiceImpl extends ServiceImpl<FormControlMapper, FormControl>implements FormControlService {

    @Override
    public int deleteById(String id){
        if(StringUtils.isEmpty(id)){
            throw new IllegalArgumentException(String.valueOf(HttpStatus.SC_METHOD_FAILURE));
        }
        return baseMapper.deleteById(id);
    }

    @Override
    public FormControl selectById(String id){
        if(StringUtils.isEmpty(id)){
            throw new IllegalArgumentException(String.valueOf(HttpStatus.SC_METHOD_FAILURE));
        }
        FormControl data=baseMapper.selectById(id);
        return data;
    }

    @Override
    public List<FormControl>selectAll(FormControl record){
        QueryWrapper<FormControl>queryWrapper=new QueryWrapper<>();
        queryWrapper.setEntity(record);
        List<FormControl>list=baseMapper.selectList(queryWrapper);
        return list;
    }

    @Override
    public IPage<FormControl>selectPage(IPage<FormControl> page , FormControl record){
        // 查询条件
        QueryWrapper<FormControl>queryWrapper=new QueryWrapper<>();
        queryWrapper.setEntity(record);
        return baseMapper.selectPage(page,queryWrapper);
    }

    @Override
    public IPage<FormControl>getPage(IPage<FormControl>page,QueryWrapper<FormControl>queryWrapper){
        return baseMapper.selectPage(page,queryWrapper);
    }

    @Override
    public FormControl findByTaskId(String taskDefinitionKey) {
        List<FormControl> taskId = baseMapper.selectList(new QueryWrapper<FormControl>() {{
            this.eq("taskId", taskDefinitionKey);
        }});
        return CollectionUtils.isEmpty(taskId)?null:taskId.get(0);
    }
}